/********************************
 * 集群基础设施监控模块
 * 创建人：徐文远
 * 创建目的：模块化JS 代码便于协同开发
 * ****************************/
$('#facilityMonitoring-endDate').text(myDate.getFullYear()+"-"+parseInt(myDate.getMonth()+1)+"-"+myDate.getDate());
$('#facilityMonitoring-start').datepicker().
on('changeDate.datepicker.amui', function(event) {
    console.log(endDate.valueOf());
    console.log(event.date.valueOf());
    if (event.date.valueOf() > endDate.valueOf()) {
        layer.alert('开始日期应小于结束日期！');
    } else {
        startDate = new Date(event.date);
        $('#facilityMonitoring-startDate').text($('#facilityMonitoring-start').data('date'));
    }
    $(this).datepicker('close');
});
$('#facilityMonitoring-end').datepicker().
on('changeDate.datepicker.amui', function(event) {
    if (event.date.valueOf() < startDate.valueOf()) {
        layer.alert('结束日期应大于开始日期！');
    } else {
        endDate = new Date(event.date);
        $('#facilityMonitoring-endDate').text($('#facilityMonitoring-end').data('date'));
    }
    $(this).datepicker('close');
});

$("#facilityMonitoringSearch").click(function() {
    $("#facilityMonitoringIsSearch").val(1);
    $("#facilityMonitoringStartDateTemp").val($("#facilityMonitoring-startDate").html());
    $("#facilityMonitoringEndDateTemp").val($("#facilityMonitoring-endDate").html());
    $("#facilityMonitoringSearchContentTemp").val($("#facilityMonitoringSearchContent").val());
});

/***************定时刷新模块 开始*********************/
var intervalId=0;
function findTr(){
	var str="";
	$("#facilityMonitoringTableList > tbody > tr").each(function(){		
		var a=$(this).children("td");		//alert(str)
		str += $(a[1]).html()+","
	});
	queryInterval(str);
	console.log(str)
	if(str==null || str==undefined||str=="")return;
	if(intervalId!=0)//清除已有的定时刷新
		clearInterval(intervalId)
	intervalId=setInterval(queryInterval,3000,str)//queryInterval(str)
}
function queryInterval(data){
	if(data==null || data==undefined )return;
	$.ajax({
        type:"get",
        url:constUrl+"cmd/jhosts/runstat.action",
        dataType:"json",
        data: {
            nodes: data
           },
        success:function(data){
        	var trs=$("#facilityMonitoringTableList > tbody > tr")
        	for(var i=0;i< trs.length;i++){
        		var tds =$(trs[i]).children("td");
        		//console.log(data[i])
        		$(tds[2]).html(data[i].hostData[0]);
        		$(tds[3]).html(data[i].hostData[2]);
        		$(tds[4]).html(data[i].hostData[4]);
        		$(tds[5]).html(data[i].hostStat[3]);
        		$(tds[6]).html(data[i].hostStat[10]);
        		$(tds[7]).html(data[i].hostStat[9]);
        	}
            //alert(data[0].hostData[2])
        },
        error:function () {
        }
        }
	);
}
/***************定时刷新模块 end*********************/